﻿// ----------------------------------------------------------------
// Description : 实体类,该文件由MyGeneration生成
// Author      : 
// Create date : 2009-12-06
// ----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace ITOMMS.Entity
{
	/// <summary>
	///	VwContract Entity
	///	VwContract Entity
	/// </summary>
	[Serializable]
	public class VwContractEntity : BaseEntity<VwContractEntity,int>
	{
		
		#region 私有成员			
		
		private int _ID; 
		private string _ContractNo; 
		private int? _ServiceID; 
		private string _ClassName; 
		private string _StraightMatter; 
		private DateTime? _EffectiveTime; 
		private DateTime? _ExpirationTime; 
		private int? _FrstParty; 
		private string _CompanyName; 
		private int? _SecondParty; 
		private DateTime? _JudgementDate; 
		private int? _AppendixID; 
		private DateTime? _CreateDate; 
		private int? _CreateBy; 
		private DateTime? _ModifyDate; 
		private int? _ModifyBy; 
		private string _Remarks; 
		private int? _State; 
		private int _SEQNO;
		#endregion


		
		#region 默认( 空 ) 构造函数
		/// <summary>
		/// 默认构造函数
		/// </summary>
		public VwContractEntity()
		{
			_ID = 0; 
			_ContractNo = String.Empty; 
			_ServiceID =  null; 
			_ClassName = String.Empty; 
			_StraightMatter = String.Empty; 
			_EffectiveTime =  null; 
			_ExpirationTime =  null; 
			_FrstParty =  null; 
			_CompanyName = String.Empty; 
			_SecondParty =  null; 
			_JudgementDate =  null; 
			_AppendixID =  null; 
			_CreateDate =  null; 
			_CreateBy =  null; 
			_ModifyDate =  null; 
			_ModifyBy =  null; 
			_Remarks = String.Empty; 
			_State =  null; 
			_SEQNO = 0;
		}
		#endregion
		
		#region 属性值校验
		
		/// <summary>
		/// 属性值校验
		/// </summary>
		public bool CheckValues()
		{
			bool bResult = true;
			string strError = "";
		
			if ( _ID ==  0)
			{
				bResult = false;
				strError += "\r\n 非空值不能为: "+_ID;
			}
			
			if( !bResult )
					throw new ArgumentOutOfRangeException(strError);
			return bResult;
			
		}
		
		#endregion
		
		
		
	
		#region Required Fields Only Constructor
		
		/// <summary>
		/// required (not null) fields only constructor
		/// </summary>
		public VwContractEntity(
		int para_ID		)
		: this()
		{
					_ID = para_ID;
			_ContractNo = String.Empty;
			_ServiceID = null;
			_ClassName = String.Empty;
			_StraightMatter = String.Empty;
			_EffectiveTime = null;
			_ExpirationTime = null;
			_FrstParty = null;
			_CompanyName = String.Empty;
			_SecondParty = null;
			_JudgementDate = null;
			_AppendixID = null;
			_CreateDate = null;
			_CreateBy = null;
			_ModifyDate = null;
			_ModifyBy = null;
			_Remarks = String.Empty;
			_State = null;
		}
		#endregion 

		
		#region 公有属性
			
			/// <summary>
			/// 行号，顺序号。系统默认的属性,对这个属性不要作操作.属性值在架构中已经处理
			/// </summary>
			public virtual int SEQNO
			{
				get { return _SEQNO; }
				set { _SEQNO = value; }
			}
		
			
		/// <summary>
		/// ID
		/// </summary>		
		public virtual int ID
		{
			get { return _ID; }
			set { _ID = value; }
		}
			
		/// <summary>
		/// ContractNo
		/// </summary>		
		public virtual string ContractNo
		{
			get { return _ContractNo; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 50)
						throw new ArgumentOutOfRangeException("Invalid value for ContractNo", value, value.ToString());
				
				_ContractNo = value;
			}
		}
			
		/// <summary>
		/// ServiceID
		/// </summary>		
		public virtual int? ServiceID
		{
			get { return _ServiceID; }
			set { _ServiceID = value; }
		}
			
		/// <summary>
		/// ClassName
		/// </summary>		
		public virtual string ClassName
		{
			get { return _ClassName; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 50)
						throw new ArgumentOutOfRangeException("Invalid value for ClassName", value, value.ToString());
				
				_ClassName = value;
			}
		}
			
		/// <summary>
		/// StraightMatter
		/// </summary>		
		public virtual string StraightMatter
		{
			get { return _StraightMatter; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 2147483647)
						throw new ArgumentOutOfRangeException("Invalid value for StraightMatter", value, value.ToString());
				
				_StraightMatter = value;
			}
		}
			
		/// <summary>
		/// EffectiveTime
		/// </summary>		
		public virtual DateTime? EffectiveTime
		{
			get { return _EffectiveTime; }
			set { _EffectiveTime = value; }
		}
			
		/// <summary>
		/// ExpirationTime
		/// </summary>		
		public virtual DateTime? ExpirationTime
		{
			get { return _ExpirationTime; }
			set { _ExpirationTime = value; }
		}
			
		/// <summary>
		/// FrstParty
		/// </summary>		
		public virtual int? FrstParty
		{
			get { return _FrstParty; }
			set { _FrstParty = value; }
		}
			
		/// <summary>
		/// CompanyName
		/// </summary>		
		public virtual string CompanyName
		{
			get { return _CompanyName; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 50)
						throw new ArgumentOutOfRangeException("Invalid value for CompanyName", value, value.ToString());
				
				_CompanyName = value;
			}
		}
			
		/// <summary>
		/// SecondParty
		/// </summary>		
		public virtual int? SecondParty
		{
			get { return _SecondParty; }
			set { _SecondParty = value; }
		}
			
		/// <summary>
		/// JudgementDate
		/// </summary>		
		public virtual DateTime? JudgementDate
		{
			get { return _JudgementDate; }
			set { _JudgementDate = value; }
		}
			
		/// <summary>
		/// AppendixID
		/// </summary>		
		public virtual int? AppendixID
		{
			get { return _AppendixID; }
			set { _AppendixID = value; }
		}
			
		/// <summary>
		/// CreateDate
		/// </summary>		
		public virtual DateTime? CreateDate
		{
			get { return _CreateDate; }
			set { _CreateDate = value; }
		}
			
		/// <summary>
		/// CreateBy
		/// </summary>		
		public virtual int? CreateBy
		{
			get { return _CreateBy; }
			set { _CreateBy = value; }
		}
			
		/// <summary>
		/// ModifyDate
		/// </summary>		
		public virtual DateTime? ModifyDate
		{
			get { return _ModifyDate; }
			set { _ModifyDate = value; }
		}
			
		/// <summary>
		/// ModifyBy
		/// </summary>		
		public virtual int? ModifyBy
		{
			get { return _ModifyBy; }
			set { _ModifyBy = value; }
		}
			
		/// <summary>
		/// Remarks
		/// </summary>		
		public virtual string Remarks
		{
			get { return _Remarks; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 100)
						throw new ArgumentOutOfRangeException("Invalid value for Remarks", value, value.ToString());
				
				_Remarks = value;
			}
		}
			
		/// <summary>
		/// State
		/// </summary>		
		public virtual int? State
		{
			get { return _State; }
			set { _State = value; }
		}
			


		#endregion 	
		
		
        #region DAO操作
		
		
		/// <summary>
        /// 获取所有实体的列表
        /// </summary>
        /// <returns></returns>
        public override List<VwContractEntity> GetAll()
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[ContractNo],[ServiceID],[ClassName],[StraightMatter],[EffectiveTime],[ExpirationTime],[FrstParty],[CompanyName],[SecondParty],[JudgementDate],[AppendixID],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State] from [Vw_Contract] ");
	
            List<VwContractEntity> list = new List<VwContractEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
				int seq = 0;
                while (dataReader.Read())
                {	seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		/// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords()
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("  select count([ID])  from [Vw_Contract] ");
	
            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }
		
		/// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords(string sqlCondition)
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("  select count([ID])  from [Vw_Contract]  ");
	
			 if (sqlCondition.Trim() != "")
            {
                strSql.Append(" where " + sqlCondition);
            }
            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }	
		
		
		/// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
		/// <param name="PageSize">每页大小</param>
		/// <param name="CurrentPageIndex">当前页码</param>
        /// <returns></returns>
		 public override List<VwContractEntity> GetAllByQuery(string strWhere, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }
		 
			strSql.Append("select top ").Append(PageSize).Append("  [ID],[ContractNo],[ServiceID],[ClassName],[StraightMatter],[EffectiveTime],[ExpirationTime],[FrstParty],[CompanyName],[SecondParty],[JudgementDate],[AppendixID],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State] from [Vw_Contract] where ");

			 if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
			  strSql.Append(" ID not in ( ");
			 strSql.Append(" select top ").Append(PageSize*(CurrentPageIndex-1)).Append("  [ID] from [Vw_Contract] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere );
            }
			strSql.Append(" ) " );

            List<VwContractEntity> list = new List<VwContractEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
			   int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }
		
		
			/// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
		/// <param name="PageSize">每页大小</param>
		/// <param name="CurrentPageIndex">当前页码</param>
		/// <param name="strSort">ex:order by id desc</param>
        /// <returns></returns>
		 public override List<VwContractEntity> GetAllByQuery(string strWhere,string strSort, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }
		 
			strSql.Append("select top ").Append(PageSize).Append("  [ID],[ContractNo],[ServiceID],[ClassName],[StraightMatter],[EffectiveTime],[ExpirationTime],[FrstParty],[CompanyName],[SecondParty],[JudgementDate],[AppendixID],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State] from [Vw_Contract] where ");

			 if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
			  strSql.Append(" ID not in ( ");
			 strSql.Append(" select top ").Append(PageSize*(CurrentPageIndex-1)).Append("  [ID] from [Vw_Contract] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere+" " ).Append(strSort);
            }
			strSql.Append(" ) " ).Append(strSort);

            List<VwContractEntity> list = new List<VwContractEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
				int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {	
					seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }
		
		
		/// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public override List<VwContractEntity> GetAllByQuery(string strWhere)
        {
			strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[ContractNo],[ServiceID],[ClassName],[StraightMatter],[EffectiveTime],[ExpirationTime],[FrstParty],[CompanyName],[SecondParty],[JudgementDate],[AppendixID],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State] from Vw_Contract ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<VwContractEntity> list = new List<VwContractEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            { 
				int seq = 0;
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		
		/// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
		/// <param name="parameters">sql条件中的参数</param>
        /// <returns></returns>
        public override List<VwContractEntity> GetAllByQuery(string strWhere, List<IDataParameter> parameters)
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[ContractNo],[ServiceID],[ClassName],[StraightMatter],[EffectiveTime],[ExpirationTime],[FrstParty],[CompanyName],[SecondParty],[JudgementDate],[AppendixID],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State] from [Vw_Contract] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<VwContractEntity> list = new List<VwContractEntity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
				int seq =0 ;
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		

		
		
		/// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<VwContractEntity> GetAllByQuery(string strWhere, List<IDataParameter> parameters, int rowNumber)
        {

            StringBuilder strSql = new StringBuilder();
			strSql.Append("select top ").Append(rowNumber).Append("  [ID],[ContractNo],[ServiceID],[ClassName],[StraightMatter],[EffectiveTime],[ExpirationTime],[FrstParty],[CompanyName],[SecondParty],[JudgementDate],[AppendixID],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State] from [Vw_Contract] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<VwContractEntity> list = new List<VwContractEntity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {	
				int seq = 0;
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		/// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句: AND AA=@AA</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<VwContractEntity> GetAllByQuery(string strWhere, int rowNumber)
        {
		    strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();
			
			strSql.Append("select top ").Append(rowNumber).Append("  [ID],[ContractNo],[ServiceID],[ClassName],[StraightMatter],[EffectiveTime],[ExpirationTime],[FrstParty],[CompanyName],[SecondParty],[JudgementDate],[AppendixID],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy],[Remarks],[State] from [Vw_Contract] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where  " + strWhere);
            }
            List<VwContractEntity> list = new List<VwContractEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
				int seq=0;
                while (dataReader.Read())
                {	
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		
		
		
			
		
		/// <summary>
        /// 对象实体绑定数据
		///生成构造为list的构造器
        /// </summary>
        private VwContractEntity ReaderBind(IDataReader dataReader,int seq)
        {
            ITOMMS.Entity.VwContractEntity entity = new ITOMMS.Entity.VwContractEntity();
			entity.SEQNO = seq;
            object obj;
						 obj=dataReader["ID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ID= (int)obj;
			}
			 entity.ContractNo= dataReader["ContractNo"].ToString();
			 obj=dataReader["ServiceID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ServiceID= (int)obj;
			}
			 entity.ClassName= dataReader["ClassName"].ToString();
			 entity.StraightMatter= dataReader["StraightMatter"].ToString();
			 obj=dataReader["EffectiveTime"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.EffectiveTime= (DateTime)obj;
			}
			 obj=dataReader["ExpirationTime"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ExpirationTime= (DateTime)obj;
			}
			 obj=dataReader["FrstParty"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.FrstParty= (int)obj;
			}
			 entity.CompanyName= dataReader["CompanyName"].ToString();
			 obj=dataReader["SecondParty"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.SecondParty= (int)obj;
			}
			 obj=dataReader["JudgementDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.JudgementDate= (DateTime)obj;
			}
			 obj=dataReader["AppendixID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.AppendixID= (int)obj;
			}
			 obj=dataReader["CreateDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateDate= (DateTime)obj;
			}
			 obj=dataReader["CreateBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateBy= (int)obj;
			}
			 obj=dataReader["ModifyDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyDate= (DateTime)obj;
			}
			 obj=dataReader["ModifyBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyBy= (int)obj;
			}
			 entity.Remarks= dataReader["Remarks"].ToString();
			 obj=dataReader["State"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.State= (int)obj;
			}

            return entity;
        }
		
		
				/// <summary>
        /// 对象实体绑定数据
		///生成构造为list的构造器
        /// </summary>
        private VwContractEntity ReaderBind(IDataReader dataReader)
        {
            ITOMMS.Entity.VwContractEntity entity = new ITOMMS.Entity.VwContractEntity();
			object obj;
						 obj=dataReader["ID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ID= (int)obj;
			}
			 entity.ContractNo= dataReader["ContractNo"].ToString();
			 obj=dataReader["ServiceID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ServiceID= (int)obj;
			}
			 entity.ClassName= dataReader["ClassName"].ToString();
			 entity.StraightMatter= dataReader["StraightMatter"].ToString();
			 obj=dataReader["EffectiveTime"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.EffectiveTime= (DateTime)obj;
			}
			 obj=dataReader["ExpirationTime"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ExpirationTime= (DateTime)obj;
			}
			 obj=dataReader["FrstParty"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.FrstParty= (int)obj;
			}
			 entity.CompanyName= dataReader["CompanyName"].ToString();
			 obj=dataReader["SecondParty"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.SecondParty= (int)obj;
			}
			 obj=dataReader["JudgementDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.JudgementDate= (DateTime)obj;
			}
			 obj=dataReader["AppendixID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.AppendixID= (int)obj;
			}
			 obj=dataReader["CreateDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateDate= (DateTime)obj;
			}
			 obj=dataReader["CreateBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateBy= (int)obj;
			}
			 obj=dataReader["ModifyDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyDate= (DateTime)obj;
			}
			 obj=dataReader["ModifyBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyBy= (int)obj;
			}
			 entity.Remarks= dataReader["Remarks"].ToString();
			 obj=dataReader["State"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.State= (int)obj;
			}

            return entity;
        }
		
		
		
		 #endregion
		
	}
}
